import React from 'react';
import ToastExample from '../module/ToastExample';
import ToastModuleB from '../module/ToastModuleB';
import { Alert, Button, NativeModules, StyleSheet, Text, View } from 'react-native';
import { vGet } from '../api/common';

type RateRecord = [number, number] // RateBadam, RateGDT

export default class HelloWorld extends React.Component {
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.hello}>Hello, World</Text>
                {/*<Text style={styles.hello}>调试</Text>*/}
                <Button title={'我是按钮'} onPress={async () => {
                    // Alert.alert("title","message")
                    // ToastExample.show("Awesome", ToastExample.SHORT);
                    // ToastModuleB.sout('留下点信息')

                    let errorCallback = args => {
                        Alert.alert('error', args);
                        console.log(args);
                    };
                    let successCallback = args => {
                        Alert.alert('success', args);
                        console.log(args);
                    };
                    // 测试传数组
                    // let rules = [0, 100];
                    // ToastModuleB.setArray(rules);

                    // promise reject
                    // try {
                    //     let result = await ToastModuleB.reject();
                    //     console.log('reject=' + result);
                    // } catch (e) {
                    //     console.warn(e);
                    // }

                    // ToastModuleB.measureLayout("app.js", errorCallback, successCallback)
                    // let result = await ToastModuleB.setMap({
                    //     'data': {
                    //         'id': 1,
                    //         'title': '我是标题',
                    //     },
                    // });
                    // console.log(result);

                    vGet('http://pl2lnxsla.bkt.clouddn.com//mock_data/homeData.json?' + (+new Date))//
                        .then(json => {
                            console.log('then');
                            ToastModuleB.setMap(JSON.parse(json));
                            // ToastModuleB.setString(json);
                        });
                    // vGet('http://assets.zvod.badambiz.com/zvod-ad18.json?' + (+new Date))
                    //     .then(json => {
                    //         ToastModuleB.setMap(JSON.parse(json));
                    //     });

                }}/>
            </View>
        );


    }

    // setMap(data) {
    //     ToastModuleB.setMap(data);
    // }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
    },
    hello: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
});

// AppRegistry.registerComponent('MyReactNativeApp', () => HelloWorld);
